葫芦的运维日志
下一篇
搜索
上一篇
浏览量 4477
2019/01/07 20:34
传引用一改皆改,传值一改改一。
点击下面 标题和删除按钮观察变化
App.vue
<!-- 1模板:html结构 -->
<template>
<div id="app">
<app-header v-bind:title1="title1"></app-header>
<users v-bind:users="users"></users>
<users v-bind:users="users"></users>
<app-footer v-bind:title1="title1"></app-footer>
</div>
</template>
<!-- 2行为:逻辑处理 -->
<script>
// 局部注册组件
import Users from './components/Users'
import Header from './components/Header'
import Footer from './components/Footer'
export default {
name: 'App',
data() {
return {
// title: "这是一个干净的脚手架项目!"
users:[
{name:"brownwang",position:"运维开发",show:false},
{name:"brownwang",position:"运维开发",show:false},
{name:"brownwang",position:"运维开发",show:false},
{name:"brownwang",position:"运维开发",show:false},
{name:"brownwang",position:"运维开发",show:false},
{name:"brownwang",position:"运维开发",show:false},
{name:"brownwang",position:"运维开发",show:false},
{name:"brownwang",position:"运维开发",show:false},
{name:"brownwang",position:"运维开发",show:false},
{name:"brownwang",position:"运维开发",show:false}],
title1:"传递的是一个值 number string boolean"
}
},
components: {
"users": Users,
"app-header": Header,
"app-footer": Footer
}
}
</script>
<!-- 3样式:解决样式 -->
<style scoped>
h1 {
color: purple;
}
</style>
Footer.vue
<template>
<footer>
<p>{{copyright}}{{title1}}</p>
</footer>
</template>
<script>
export default {
name: 'app-footer',
props:{
title1:{
type:String
}
},
data () {
return {
copyright:'Copyright 2019 Vue Demo'
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
footer{
background:#222;
padding:6px;
}
p{
color:lightgreen;
text-align:center;
}
</style>
Header.vue
<template>
<header v-on:click="changetitle">
<h1>{{title}}{{title1}}</h1>
</header>
</template>
<script>
export default {
name: 'app-header',
props: {
title1: {
type: String
}
},
data() {
return {
title: 'Vue.js Demo'
}
},
methods: {
changetitle: function () {
this.title1 = 'changed';
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
header {
background: lightgreen;
padding: 10px;
}
h1 {
color: #222;
text-align: center;
}
</style>
葫芦的运维日志
打赏
上一篇
搜索
下一篇